package com.ruoyi.web.core.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;


/**
 * Swagger2的接口配置
 * 
 * @author ruoyi
 */
@Configuration
@EnableKnife4j
public class SwaggerConfig
{
    private final OpenApiExtensionResolver openApiExtensionResolver;

    @Autowired
    public SwaggerConfig(OpenApiExtensionResolver openApiExtensionResolver) {
        this.openApiExtensionResolver = openApiExtensionResolver;
    }
    /**
     * 创建Docket逻辑分组
     */
    @Bean(value = "systemSwagger")
    public Docket system(){
        return docket("系统管理","com.ruoyi.web");
    }
    /**
     * 创建Docket逻辑分组
     */
    @Bean(value = "systemDemo")
    public Docket demo(){
        return docket("示例","com.ruoyi.demo");
    }

    /**
     *
     */
    private Docket docket(String groupName,String basePackage)
    {
        // 用ApiInfoBuilder进行定制
        ApiInfo api = new ApiInfoBuilder()
                // 设置标题
                .title(groupName)
                .build();
        Docket docket=new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(api)
                .groupName(groupName)
                .select()
                .apis(RequestHandlerSelectors.basePackage(basePackage))
                .paths(PathSelectors.any())
                .build()
                .extensions(openApiExtensionResolver.buildSettingExtensions());
        return docket;
    }
}
